﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;

namespace EOS.Framework.Web.Mvc
{
    [Serializable, AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class ParameterDictionary : Dictionary<string, object>
    {
        public ParameterDictionary()
            : base(StringComparer.OrdinalIgnoreCase)
        { }

        public ParameterDictionary(IDictionary<string, object> dictionary)
            : base(dictionary, StringComparer.OrdinalIgnoreCase)
        { }

        public ParameterDictionary(object values)
            : base(StringComparer.OrdinalIgnoreCase)
        {
            this.AddValues(values);
        }

        private void AddValues(object values)
        {
            if (values != null)
            {
                foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(values))
                {
                    object obj = descriptor.GetValue(values);
                    base.Add(descriptor.Name, obj);
                }
            }
        }
    }
}
